﻿using System;
using System.Windows.Forms;
using DevelopersToolbox;
using SqlFormat.Rtf;

namespace SqlTools {
    public partial class SqlFormatControl : UserControl, IExecutableTool {
        public SqlFormatControl() {
            InitializeComponent();
        }

        private void _formatButton_Click(object sender, EventArgs e) {
            Execute();
        }

        public void Execute() {
            try {
                RtfSqlFormatterOptions options = new RtfSqlFormatterOptions();
                options.Multiline = true;
                RtfSqlFormatter formatter = new RtfSqlFormatter(options);
                string formatedText = formatter.Format(_sql.Text);
                _formattedSql.Rtf = formatedText;
            }
            catch (Exception ex) {
                _formattedSql.Text = ex.ToString();
            }
        }
    }
}